#lang racket


(require "../base/main.rkt")

(require "differenciation.rkt"
         "parametric.rkt")

(provide (struct-out skin)
         skin-tangent
         skin-normal
         skin-binormal
         make-simple-skin)


(define-struct (skin parametric) ())

(define (skin-tangent object-fn)
  (λ (u v)
    (differenciate-tangent object-fn u v)))

(define (skin-normal object-fn)
  (λ (u v)
    (let* ((ts (differenciate-tangent object-fn u v))
           (u (first ts))
           (v (second ts)))
      (cross-c u v))))

(define (skin-binormal)
  (λ (u v)
    (raise unsupported "Binormal is undefined for skins")))

(define (make-simple-skin object-fn domain)
  (make-skin
   object-fn
   (skin-tangent object-fn)
   (skin-normal object-fn)
   (skin-binormal)
   domain))